package com.lw.biz.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lw.base.client.result.BaseResult;
import com.lw.biz.client.model.BizDataCommentModel;
import com.lw.biz.client.model.BizDataModel;
import com.lw.biz.client.service.IBizDataCommentService;
import com.lw.biz.dal.dao.BizDataCommentDao;
import com.lw.biz.dal.entity.BizData;
import com.lw.biz.dal.entity.BizDataComment;
import com.lw.biz.dal.enums.GtOrLtEnum;
import com.lw.biz.dal.enums.SortEnum;

@Service("iBizDataCommentService")
public class IBizDataCommentServiceImpl implements IBizDataCommentService {

	@Autowired
	private BizDataCommentDao bizDataCommentDao;

	public BaseResult<List<BizDataCommentModel>> getListGtIdAndDesc(Long id, Long dataId, int offset) {
		try {
			List<BizDataComment> dbList = bizDataCommentDao.selectDataCommentByOffset(id, dataId, offset, GtOrLtEnum.GT, SortEnum.DESC);
			List<BizDataCommentModel> reList = new ArrayList<BizDataCommentModel>();
			for(BizDataComment bizDataComment : dbList){
				BizDataCommentModel bizDataCommentModel = new BizDataCommentModel();
				BeanUtils.copyProperties(bizDataComment, bizDataCommentModel);
				reList.add(bizDataCommentModel);
			}
			return new BaseResult<List<BizDataCommentModel>>(reList);
		} catch (Exception e) {
			e.printStackTrace();
			return new BaseResult<List<BizDataCommentModel>>(null,BaseResult.FAIL,false,e.getMessage());
		}
	}

	public BaseResult<List<BizDataCommentModel>> getListGtIdAndAsc(Long id, Long dataId, int offset) {
		try {
			List<BizDataComment> dbList = bizDataCommentDao.selectDataCommentByOffset(id, dataId, offset, GtOrLtEnum.LT, SortEnum.ASC);
			List<BizDataCommentModel> reList = new ArrayList<BizDataCommentModel>();
			for(BizDataComment bizDataComment : dbList){
				BizDataCommentModel bizDataCommentModel = new BizDataCommentModel();
				BeanUtils.copyProperties(bizDataComment, bizDataCommentModel);
				reList.add(bizDataCommentModel);
			}
			return new BaseResult<List<BizDataCommentModel>>(reList);
		} catch (Exception e) {
			e.printStackTrace();
			return new BaseResult<List<BizDataCommentModel>>(null,BaseResult.FAIL,false,e.getMessage());
		}
	}

	public BaseResult<List<BizDataCommentModel>> getListLtIdAndDesc(Long id, Long dataId, int offset) {
		try {
			List<BizDataComment> dbList = bizDataCommentDao.selectDataCommentByOffset(id, dataId, offset, GtOrLtEnum.LT, SortEnum.ASC);
			List<BizDataCommentModel> reList = new ArrayList<BizDataCommentModel>();
			for(BizDataComment bizDataComment : dbList){
				BizDataCommentModel bizDataCommentModel = new BizDataCommentModel();
				BeanUtils.copyProperties(bizDataComment, bizDataCommentModel);
				reList.add(bizDataCommentModel);
			}
			return new BaseResult<List<BizDataCommentModel>>(reList);
		} catch (Exception e) {
			e.printStackTrace();
			return new BaseResult<List<BizDataCommentModel>>(null,BaseResult.FAIL,false,e.getMessage());
		}
	}

	public BaseResult<List<BizDataCommentModel>> getListLtIdAndAsc(Long id, Long dataId, int offset) {
		try {
			List<BizDataComment> dbList = bizDataCommentDao.selectDataCommentByOffset(id, dataId, offset, GtOrLtEnum.GT, SortEnum.DESC);
			List<BizDataCommentModel> reList = new ArrayList<BizDataCommentModel>();
			for(BizDataComment bizDataComment : dbList){
				BizDataCommentModel bizDataCommentModel = new BizDataCommentModel();
				BeanUtils.copyProperties(bizDataComment, bizDataCommentModel);
				reList.add(bizDataCommentModel);
			}
			return new BaseResult<List<BizDataCommentModel>>(reList);
		} catch (Exception e) {
			e.printStackTrace();
			return new BaseResult<List<BizDataCommentModel>>(null,BaseResult.FAIL,false,e.getMessage());
		}
	}



}
